<?php

namespace moonlight\slide\actions;

use Yii;
use moonlight\slide\SlideValidateConfig;
use moonlight\slide\SlideValidateCore;
use yii\base\Action;

/**
 * Class StartAction 滑动验证初始化动作
 */
class StartAction extends Action
{
    /**
     * @inheritdoc
     */
    public function run()
    {
        $validate = new SlideValidateCore(SlideValidateConfig::CAPTCHA_ID, SlideValidateConfig::PRIVATE_KEY);
        $key = rand(1, 99999);
        $status = $validate->preProcess($key);

        $session = Yii::$app->getSession();
        $session->set('gtserver', $status);
        $session->set('user_id', $key);

        return $validate->getResponseStr();
    }
}